<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{ background-color: #F7F8FA; height:100%; }
			.add_card h2{ display:block; padding: 10px 15px; font-size: 12px; line-height: 25px; font-weight: 400; color: #808080;}
			.add_card li{ position: relative;background-color:#fff; padding:0 15px;}
			.add_card li:not(:last-child)::after{ display:block; content: ""; position: absolute; left: 0; right: 0; bottom: 0; overflow: hidden; height: 1px; background-color: #ededed; -webkit-transform: scaleY(.5); transform: scaleY(.5);}
			.add_card input{ display:block; border:0;  width: 100%; height: 50px; line-height: 50px; font-size: 14px; color: #333; }
			.add_card .con{ padding: 0;}
			.add_card .con a{ float:left; padding: 10px;}
			.add_card .con img{ width:0.34rem;}
			.add_card .con p{ float:right; font-size: 12px; color: #222; line-height: 35px;}
			
		</style>
	</head>
	<body>
		<div class="add_card add_card01">
			<h2>你需要发送验证申请，等待对方通过</h2>
			<ul>
				<li id="lititle"><input type="text" value="" id="msg" readonly placeholder="请输入验证信息" /></li>
			</ul>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript">
		var dfuid;
		var keyboardId = 0;//当前键盘ID
		var UIInput;
		apiready = function() {
			api.parseTapmode();
			dfuid = api.pageParam.dfuid;
			UIInput = api.require('UIInput');
			fnInitUIInput(); //初始化键盘
			
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
				else if (ret.type == 'right') {
					sendinvite();
                }
            });
		}
		function sendinvite() {
			hideInput();//收起键盘
			var msg = $api.val($api.byId('msg'));
			
			if(msg=='')
			{
				toast("请输入验证信息");
				return false;
			}
			//发送请求
			api.showProgress({
				title: '请稍后...',
				text: '',
				modal: true
			});
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/friendlogs',
						method: 'post',
						cache: false,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						},
						data: {
							values: {
								dfuid: dfuid,
								type: 'addfriend',
								msg: msg
							}
						}
					}, function(ret, err) {
						api.hideProgress();
						if (ret) {
							api.alert({
								title: '提示',
								msg: '验证信息已发送，等待对方通过！',
							}, function(ret, err) {
								if(ret.buttonIndex == 1)
								{
									api.closeWin({
									});
								}
							});
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								//toast('网络异常');
							}
						}
					});
				}
			});
		}
		function fnInitUIInput(){
			//计算位置
			openUIinput('msg',1,'请输入验证信息',1,'default',true,'text',50);
		}
		function openUIinput(domid,y_str,placeholder_str,rownum,keyboardType,iscenter,inputType,maxnum){
			//打开UIinput
			var UIInput = api.require('UIInput');
			var password = $api.byId(domid);
			var password_rect = $api.offset(password);
			UIInput.open({
				rect: {
					x: password_rect.l,
					y: password_rect.t+y_str,
					w: password_rect.w,
					h: password_rect.h-2
				},
				styles: {
					bgColor: '#fff',
					size: 15,
					color: '#000',
					placeholder: {
						color: '#999'
					}
				},
				autoFocus: true,
				maxRows: rownum,
				placeholder: placeholder_str,
				keyboardType: keyboardType,
				isCenterVertical: iscenter,
				inputType: inputType,
				fixedOn: api.frameName,
				fixed: false
			}, function(ret) {
				var id2 = ret.id;
				if(ret.eventType == 'show') {
					keyboardId = ret.id;

				} else if (ret.eventType == 'change') {
					keyboardId = ret.id;
					UIInput.value({
							id: ret.id,
							//msg : '设置输入框的值'
					}, function(ret, err) {
						if (ret) {
							var _msg = ret.msg;
							var _msglen = _msg.length;
							if(_msglen > maxnum)
							{
								_msglen = maxnum;
								_msg = ret.msg.substr(0,maxnum);
								UIInput.value({
									id: keyboardId,
									msg: _msg
								});
							}
							if(domid == 'content')
							{
								$api.text($api.dom('#msgts'),_msglen+'/5000');
							}
							$api.val(password,_msg);
						} else {
							//alert(JSON.stringify(err));
						}
					});
				
				
				
					
				} else {
					//alert(JSON.stringify(ret));
				}
			});
			
		}
		function hideInput(){
			//隐藏键盘
			UIInput.closeKeyboard({
				id: keyboardId
			});
		}
		
	</script>
</html>